<?php
/**
 * Created by PhpStorm.
 * User: u
 * Date: 2018/12/14
 * Time: 19:12
 */
namespace common\logics\classifyreason;

use common\widgets\Tool;
use Yii;
use yii\base\BaseObject;

class ClassifyReasonLogic extends BaseObject implements IClassifyReason
{
    /** @var \common\sources\read\classifyreason\ClassifyReasonAccess $RClassifyReasonAccess **/
    private $RClassifyReasonAccess;
    /** @var \common\sources\write\classifyreason\ClassifyReasonAccess $WClassifyReasonAccess **/
    private  $WClassifyReasonAccess;

    public function init()
    {
        $this->RClassifyReasonAccess = Yii::$container->get("RClassifyReasonAccess");
        $this->WClassifyReasonAccess = Yii::$container->get("WClassifyReasonAccess");
        parent::init(); // TODO: Change the autogenerated stub
    }
    //获取列表
    public function getList($data)
    {
        if(empty($data['audit_type'])){
            return Tool::returnJson([],401,"审核分类不能为空");
        }
        $list = $this->RClassifyReasonAccess->getList($data);
        //分类
        $audit_status = Yii::$app->params['audit_manage'];
        $data['list'] = $list;
        $data['audit_status'] = $audit_status;
        return Tool::returnJson($data,200,"成功");
    }
    //添加分类原因
    public function addClassifyReason($data)
    {
        if(empty($data['audit_type'])){
            return Tool::returnJson([],401,"审核分类不能为空");
        }
        if(empty($data['class_name'])){
            return Tool::returnJson([],402,"审核分类名称不能为空");
        }
        if(empty($data['classify_id'])){
            return Tool::returnJson([],403,"审核分类id不能为空");
        }
        if(empty($data['reason'])){
            return Tool::returnJson([],405,"审核分类原因不能为空");
        }
        //添加审核原因
        $result =  $this->WClassifyReasonAccess->addClassifyReason($data);
        if($result){
            return Tool::returnJson([],200,"添加审核原因成功");
        }
        return Tool::returnJson([],406,"添加审核原因失败");
    }
    //修改审核原因
    public function modifyClassifyReason($data)
    {
        if(empty($data['c_id'])){
            return Tool::returnJson([],401,"审核分类id不能为空");
        }
        if(empty($data['class_name'])){
            return Tool::returnJson([],402,"分类名称不能为空");
        }
        if(empty($data['classify_id'])){
            return Tool::returnJson([],403,"审核分类id不能为空");
        }
        if(empty($data['reason'])){
            return Tool::returnJson([],405,"审核原因不能为空");
        }
        //修改分类
        $result = $this->WClassifyReasonAccess->modifyClassifyReason($data);
        if($result){
            return Tool::returnJson([],200,"修改成功");
        }
        return Tool::returnJson([],406,"修改失败");
    }
    //删除审核原因
    public function delClassifyReason($data)
    {
        if(empty($data['c_id'])){
            return Tool::returnJson([],401,"审核分类id不能为空");
        }
        $result = $this->WClassifyReasonAccess->delClassifyReason($data);
        if($result){
            return Tool::returnJson([],200, "删除成功");
        }
        return Tool::returnJson([],402,"删除失败");
    }
}